package com.wy2cloud.authorize.controller;

import java.security.Principal;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;


/**
 * 主控制器
 * @author wuyy<16349023@qq.com>,nnsword
 * @date 2018年4月3日下午4:53:53
 *
 */
@Controller
public class HomeController {

    @RequestMapping(value= {"","/"})
    public String index(Model model,Principal principal) {
        model.addAttribute("userName", principal.getName());
        return "index";
    }
    
	@GetMapping("/login")
    public String login(Model model,@RequestParam(value = "error", required = false) String error,
            @RequestParam(value = "logout", required = false) String logout) {
		if (error != null) {
            model.addAttribute("error", "不正确的用户名和密码");
        }
        if (logout != null) {
            model.addAttribute("msg", "你已经成功退出");
        }
        //applicationContext.publishEvent(new MessageEvent(this, 0, "访问了管理登录页面"));
        model.addAttribute("title", "title");
        model.addAttribute("name", "hello");
        return "login";
    }
}
